/********************************************************************************/
/*		EncodedStructs.h:														*/
/********************************************************************************/


/*
UPDATES:
	2/14/12 - Created initial file. This is parts of the old Decoded Structs file. 
		We still need to add some functions. These functions will take a struct
		(or class) and based on the opcode and other strings passed inside, set the 
		individual bit fields.
			Still not sure whether to use enum or hash tables for those functions.
			Will look into it later (Anastasia Shuba)
*/
#ifndef DECODEDSTRUCTS_H
#define DECODEDSTRUCTS_H
#include "hashtbl.h"
#include "AssemblerClasses.h"
#include <vector>
#include <string>

using std::vector;
using std::string;
/* Output vector. Each int is an instruction */
//vector<int> EnInsts;

/* Type Definitions */

typedef struct r RTYPE;
typedef struct i ITYPE;
typedef struct j JTYPE;
typedef struct f4 FUNCT4;
typedef struct b17 BIT17; 

/* R Type Structure */
struct r
{
	unsigned int funct : 6;
    unsigned int fd : 5; 
    unsigned int rd : 5;
    unsigned int rt : 5;
    unsigned int rs : 5;
    unsigned int opcode : 6;
};

/* I Type Structure */
struct i
{
	unsigned int offset : 16; 
	unsigned int tal: 2;
	unsigned int cc : 3;
	unsigned int rs : 5;
	unsigned int opcode : 6;
};

/* J Type Structure, can also be used as dummy */
struct j
{
	unsigned int target : 26;
	unsigned int opcode : 6;
};

struct b17
{
	unsigned int baz : 16;
	unsigned int a : 1;
	unsigned int foo : 15;
};

struct f4
{
	unsigned int funct : 5;
	unsigned int pad : 21;
	unsigned int opcode : 6;
};

/* This union will be populated with the RTYPE, ITYPE, and JTYPE */
/* structs for quick dividing of bits */
typedef union Instruction 
{
	unsigned int instruction;
  	RTYPE R;
  	ITYPE I;
    JTYPE J;
	FUNCT4 F4;
    BIT17 B17;
}INSTU;

class numbers
{
	public:
		numbers()
		{
			reg=0;
		}

		unsigned int reg;
};

class Decoded
{
	public:
		Decoded()
		{
			string opcode;
			string reg1;
			string reg2;
			string reg3;
		}

        string opcode;
        string reg1;
        string reg2;
        string reg3;

};

void HashOpcode(HashTbl *tbl);

void HashRegister(HashTbl *tbl);

int setRegisters(INSTU *u, Decoded d, HashTbl *tbl, AssemblerData &ASM, int i, vector<string> code);

#endif
